#pragma once

#include "CrossDefine.h"
#include "BaseFunc.h"
#include <string>
#include <vector>


typedef int (*fn_make_string)(const void* p_obj, std::string& str);
int int_2_string(const void* p_obj, std::string& str);
int float_2_string(const void* p_obj, std::string& str);
int string_2_string(const void* p_obj, std::string& str);

//typedef std::vector<int> CT;

template <typename CT>
int make_csv_vec( const CT &vals, std::string& str, fn_make_string p_fn )
{
	str.clear();
	for_std_const_unit_template (CT, vals)
	{
		std::string sub_str;
		p_fn(&(*it), sub_str);

		str += "(" + sub_str + ")";
	}
	return (int)str.size();
}

template <class CCT>
int make_csv_vec_vec( const CCT &vals, std::string& str, fn_make_string p_fn )
{
	str.clear();
	for_std_const_unit_template (CCT, vals)
	{
		std::string sub_str;
		std::string elem_str;
		for_std_const_unit_it_template (CCT::value_type, (*it), it_sub)
		{
			p_fn(&(*it_sub), elem_str);

			if (!sub_str.empty())
				sub_str += '|';
			sub_str += elem_str;
		}
		str += "(" + sub_str + ")";
	}
	return (int)str.size();
}

template <class CCT>
int make_csv_map_vec( const CCT &vals, std::string& str, fn_make_string p_fn )
{
	str.clear();
	for_std_const_unit_template (CCT, vals)
	{
		std::string sub_str;
		std::string elem_str;
		for_std_const_unit_it_template (CCT::mapped_type, (it->second), it_sub)
		{
			p_fn(&(*it_sub), elem_str);

			if (!sub_str.empty())
				sub_str += '|';
			sub_str += elem_str;
		}
		str += "(" + sub_str + ")";
	}
	return (int)str.size();
}

int read_csv_vector(std::vector < std::vector <std::string>  >  &vals, const char *sz);
int read_csv_vector_float(std::vector < std::vector <float>  >  &vals, int size, const char *sz);


const char* parse_scanf(const char* psz_data, const char* fmt, int va_len, ...);